package com.tanhua.server.controller;

import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.UserInfoVo;
import com.tanhua.server.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/messages")
public class MessageController {

    @Autowired
    private MessageService messageService;

    /**
     * 根据环信用户id查询用户详情
     */
    @GetMapping("/userinfo")
    public ResponseEntity userinfo(String huanxinId) {
        UserInfoVo vo = messageService.findUserInfoByHuanxinId(huanxinId);
        return ResponseEntity.ok(vo);
    }

    /**
     * 添加好友
     */
    @PostMapping("/contacts")
    public ResponseEntity contacts(@RequestBody Map map) {
        String userId = map.get("userId").toString();
        Long id = Long.valueOf(userId);
        messageService.contacts(id);
        return ResponseEntity.ok(null);
    }

    /**
     * 分页查询联系人列表
     */
    @GetMapping("/contacts")
    public ResponseEntity contacts(String keyword, @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pagesize) {
        PageResult pageResult = messageService.findFriends(page, pagesize, keyword);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 分页查询评论列表
     */
    @GetMapping("/comments")
    public ResponseEntity comments(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pagesize) {
        PageResult pr = messageService.findComments(page, pagesize);
        return ResponseEntity.ok(pr);
    }

    /**
     * 分页查询点赞列表
     */
    @GetMapping("/likes")
    public ResponseEntity likes(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pagesize) {
        PageResult pr = messageService.findLikes(page, pagesize);
        return ResponseEntity.ok(pr);
    }

    /**
     * 分页查询喜欢列表
     */
    @GetMapping("/loves")
    public ResponseEntity loves(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pagesize) {
        PageResult pr = messageService.findLoves(page, pagesize);
        return ResponseEntity.ok(pr);
    }

    /**
     * 查询公告
     */
    @GetMapping("/announcements")
    public ResponseEntity announcements(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pagesize){
        PageResult pr = messageService.announcements(page,pagesize);
        return ResponseEntity.ok(pr);
    }
}
